package com.demo.lambdaAndFunctionReference;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.function.DoublePredicate;
import java.util.function.DoubleUnaryOperator;

public class Main {

    private static List<Apple> getAppleList() {
        List<Apple> inventory = new ArrayList<>();
        Random random = new Random();
        String[] colors = {"red", "green", "yellow"};
        Apple apple = null;
        for(int i = 0; i < 20; i++) {
            apple = new Apple();
            apple.setColor(colors[random.nextInt(3)]);
            apple.setWeight(random.nextInt(400));
            inventory.add(apple);
        }
        return inventory;
    }

    public static void main(String[] args) {
        List<Apple> inventory = getAppleList();
        System.out.println(inventory);
        inventory.sort(Comparator.comparing(Apple::getWeight));
        System.out.println(inventory);
        inventory.sort(Comparator.comparing(Apple::getWeight).reversed());
        System.out.println(inventory);

        DoubleUnaryOperator doubleUnaryOperator = (x) -> x / 2;

        double result = doubleUnaryOperator.applyAsDouble(3);
        System.out.println(result);
    }
}
